<?php
/**************************************************************************
 *
 *   Copyright 2010 American Public Media Group
 *
 *   This file is part of AIR2.
 *
 *   AIR2 is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   AIR2 is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with AIR2.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/

require_once 'AIR2_CRUD_Controller.php';

/**
 * Response Controller
 *
 * API-only (no html) controller for SrcResponse objects.  This allows CRUD
 * operations on a single response, and SrAnnotations.
 *
 * @author rcavis
 * @package default
 */
class Response_Controller extends AIR2_CRUD_Controller {

    public $base_model_name = 'SrcResponse';
    //public $base_view_name  = 'response';
    public $exposed_relations = array(
        'annotations' => 'SrAnnotation',
    );


    /**
     * Add custom relations to queries to this controller
     *
     * @param AIR2_Query $q
     * @param boolean $deeply (optional)
     */
    protected function _add_query_load_related(&$q, $deeply=true) {
        if (!$this->rel_uri) {

        }
        elseif ($this->rel_uri === 'annotations') {
            $q->leftJoin('a.CreUser c');
            $q->leftJoin('c.UserOrg uo WITH uo.uo_home_flag = true');
            $q->leftJoin('uo.Organization o');
        }
        parent::_add_query_load_related($q, $deeply);
    }


}
